﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.ComponentModel;

namespace CPAScoringPerformanceTester.TestTask
{
    /// <summary>
    /// ScoreTaskApplyTaskWindow.xaml 的交互逻辑
    /// </summary>
    public partial class ScoreTaskApplyTaskWindow : Window, INotifyPropertyChanged
    {
        private int repeatCount;
        public int RepeatCount
        {
            get { return repeatCount; }
            set
            {
                if (value == repeatCount || repeatCount < 0) return;
                repeatCount = value;
                OnPropertyChanged("RepeatCount");
            }
        }

        private bool noPriority;
        public bool NoPriority
        {
            get { return noPriority; }
            set
            {
                noPriority = value;
                OnPropertyChanged("NoPriority");
            }
        }

        private bool allPriority;
        public bool AllPriority
        {
            get { return allPriority; }
            set
            {
                allPriority = value;
                OnPropertyChanged("AllPriority");
            }
        }

        private bool randomPriority;
        public bool RandomPriority
        {
            get { return randomPriority; }
            set
            {
                randomPriority = value;
                OnPropertyChanged("RandomPriority");
            }
        }

        private int applyCount;
        public int ApplyCount
        {
            get { return applyCount; }
            set
            {
                applyCount = value;
                OnPropertyChanged("ApplyCount");
            }
        }

        public RelayCommand ApplyCommand { get; set; }
        public RelayCommand CloseCommand { get; set; }
        public event PropertyChangedEventHandler PropertyChanged;

        public ScoreTaskApplyTaskWindow()
        {
            CloseCommand = new RelayCommand(() => this.Close());
            ApplyCommand = new RelayCommand(Apply);
            InitializeComponent();
            RepeatCount = ScoreTaskApplySettings.Instance.RepeatCount;
            NoPriority = ScoreTaskApplySettings.Instance.NoPriority;
            AllPriority = ScoreTaskApplySettings.Instance.AllPriority;
            RandomPriority = ScoreTaskApplySettings.Instance.RandomPriority;
            ApplyCount = ScoreTaskApplySettings.Instance.ApplyCount;
        }

        private void Apply()
        {
            ScoreTaskApplySettings.Instance.RepeatCount = RepeatCount;
            ScoreTaskApplySettings.Instance.NoPriority = NoPriority;
            ScoreTaskApplySettings.Instance.AllPriority = AllPriority;
            ScoreTaskApplySettings.Instance.RandomPriority = RandomPriority;
            ScoreTaskApplySettings.Instance.ApplyCount = ApplyCount;
            this.Close();
        }

        private void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
